﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnalisisDeRiesgosConfiguration.Model;
using AnalisisDeRiesgosConfiguration.DataAccess;

namespace AnalisisDeRiesgosConfiguration.Controller
{
    class RegisterDataController
    {
        DatabaseConnectionString connectionString;

        public RegisterDataController(string password, string url)
        {
            connectionString = new DatabaseConnectionString(password, url);
        }

        public void ExecuteScript(string username)
        {
            if (String.IsNullOrEmpty(username))
                throw new ArgumentException("El nombre de usuario no puede ser nulo o vacio", "username");
            ScriptExecutor executor = new ScriptExecutor(connectionString);

            executor.CreateDataBase();
            executor.AssignPermissions(username);
        }

        public void RegisterUser(User theUser)
        {
            theUser.Validate();
            UserDataAccess dataAccess = new UserDataAccess(connectionString);

            dataAccess.CreateUser(theUser);
        }

        public void RegisterManagement(Management theManagement)
        {
            theManagement.Validate();
            ManagementDataAccess dataAccess = new ManagementDataAccess(connectionString);

            dataAccess.CreateManagement(theManagement);
        }
    }
}
